<template>
  <rj-modal :visible="show" :footer="null" @cancel="handleCancel">
    <div style="padding: 15px">
      {{ $t('enetPwd.tip5', [account, account]) }}
    </div>
    <div class="btns">
      <rj-space>
        <a-button type="primary" @click="saveStatus(1)">
          {{ $t('enetPwd.agree') }}
        </a-button>
        <a-button @click="saveCancel()">{{
          $t('groupOperate.getreject')
        }}</a-button>
      </rj-space>
    </div>
  </rj-modal>
</template>
<script>
import { RjModal } from '@components';
import { requestHttp, maccApi } from '@utils/index';
import { mapState } from 'vuex';
export default {
  name: 'ProjectResponseApply',
  props: {
    account: {
      type: String,
      default: '',
    },
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {
    ...mapState('Theme', ['theme']),
  },
  components: {
    RjModal,
  },
  methods: {
    handleCancel() {
      this.$emit('close');
    },
    saveCancel() {
      this.$confirm({
        title: this.$t('upgradeLog.ok'),
        content:
          this.$t('enetPwd.reject') + this.account + this.$t('enetPwd.tip6'),
        onOk: async () => {
          this.saveStatus(0);
        },
      });
    },
    async saveStatus(state) {
      const api = maccApi.PROJECT_ACCOUNT_TOCONFIRM_POST_API.replace(
        '{state}',
        state
      );
      const { code, msg = this.$t('enetPwd.failMerge') } = await requestHttp({
        api,
        method: 'POST',
        params: { state: state },
      });
      if (code === 0) {
        this.triggerAccountListUpdata();
        this.handleCancel();
        this.$emit('toconFirm');
      } else {
        this.$message.error(msg);
      }
    },
    triggerAccountListUpdata() {
      if (['RUIYI', 'RUIYI_V2'].includes(this.theme)) {
        return;
      }
      //TODO NOC刷新租户列表？
    },
  },
};
</script>
<style lang="less" scoped>
.btns {
  display: flex;
  justify-content: flex-end;
}
</style>
